package com.oauth.authorization.controller;

import com.oauth.authorization.vo.UserGetDetailVO;
import com.oauth.common.api.BaseResponse;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 认证前端控制器
 *
 * @author duchao
 */
@Slf4j
@RequestMapping("oauth")
@RestController
public class OauthController {

    @PostMapping(value = "xWwwFormUrlencoded", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public BaseResponse<Map<String, Object>> test1(@RequestParam("id") Integer id, @RequestParam("name") String name) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        log.info("入参：map={}", map);
        return BaseResponse.success(map);
    }

    @RequestMapping(value = "xWwwFormUrlencoded2", method = {RequestMethod.GET, RequestMethod.POST}, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public BaseResponse<String> xWwwFormUrlencoded2(@RequestBody(required = false) String content) {
        log.info("入参：content={}", content);
        return BaseResponse.success(content);
    }

    @PostMapping(value = "json1", consumes = MediaType.APPLICATION_JSON_VALUE)
    public BaseResponse<UserGetDetailVO> json1(@RequestBody UserGetDetailVO vo) {
        log.info("请求体：{}", vo);
        return BaseResponse.success(vo);
    }

    @PostMapping(value = "json2", consumes = MediaType.APPLICATION_JSON_VALUE)
    public BaseResponse<String> json2(@RequestBody String content) {
        log.info("请求体：{}", content);
        return BaseResponse.success(content);
    }

    @PostMapping(value = "text1", consumes = MediaType.TEXT_PLAIN_VALUE)
    public BaseResponse<String> text1(@RequestBody String content) {
        log.info("请求体：{}", content);
        return BaseResponse.success(content);
    }

    @PostMapping(value = "form1", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public BaseResponse<Map<String, Object>> form1(@RequestParam("id") Integer id, @RequestParam("name") String name) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        log.info("入参：map={}", map);
        return BaseResponse.success(map);
    }

}
